package br.valstorm.model;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 *
 * @author rgrunitzki
 */
@Entity
@Table(name = "projects")
public class Project implements Serializable {

    @Id
    @GeneratedValue
    @Column(name = "id_project")
    private long id;

    @Column(name = "ds_name")
    private String name;

    @ManyToOne
    @JoinColumn(name = "id_user", nullable = true)
    private User projectController;
    @ManyToMany(mappedBy = "projects")
    private List<User> projectViewers;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public User getProjectController() {
        return projectController;
    }

    public void setProjectController(User projectController) {
        this.projectController = projectController;
    }

    public List<User> getProjectViewers() {
        return projectViewers;
    }

    public void setProjectViewers(List<User> projectViewers) {
        this.projectViewers = projectViewers;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 17 * hash + (int) (this.id ^ (this.id >>> 32));
        hash = 17 * hash + Objects.hashCode(this.name);
        hash = 17 * hash + Objects.hashCode(this.projectController);
        hash = 17 * hash + Objects.hashCode(this.projectViewers);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Project other = (Project) obj;
        if (this.id != other.id) {
            return false;
        }
        if (!Objects.equals(this.name, other.name)) {
            return false;
        }
        if (!Objects.equals(this.projectController, other.projectController)) {
            return false;
        }
        return Objects.equals(this.projectViewers, other.projectViewers);
    }
}
